1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdk.Cursor; 26 27 private import gdk.Texture; 28 private import gdk.c.functions; 29 public import gdk.c.types; 30 private import glib.ConstructionException; 31 private import glib.Str; 32 private import glib.c.functions; 33 private import gobject.ObjectG; 34 35 36 /** 37 * `GdkCursor` is used to create and destroy cursors. 38 * 39 * Cursors are immutable objects, so once you created them, there is no way 40 * to modify them later. You should create a new cursor when you want to change 41 * something about it. 42 * 43 * Cursors by themselves are not very interesting: they must be bound to a 44 * window for users to see them. This is done with [method@Gdk.Surface.set_cursor] 45 * or [method@Gdk.Surface.set_device_cursor]. Applications will typically 46 * use higher-level GTK functions such as [method@Gtk.Widget.set_cursor] instead. 47 * 48 * Cursors are not bound to a given [class@Gdk.Display], so they can be shared. 49 * However, the appearance of cursors may vary when used on different 50 * platforms. 51 * 52 * ## Named and texture cursors 53 * 54 * There are multiple ways to create cursors. The platform's own cursors 55 * can be created with [ctor@Gdk.Cursor.new_from_name]. That function lists 56 * the commonly available names that are shared with the CSS specification. 57 * Other names may be available, depending on the platform in use. On some 58 * platforms, what images are used for named cursors may be influenced by 59 * the cursor theme. 60 * 61 * Another option to create a cursor is to use [ctor@Gdk.Cursor.new_from_texture] 62 * and provide an image to use for the cursor. 63 * 64 * To ease work with unsupported cursors, a fallback cursor can be provided. 65 * If a [class@Gdk.Surface] cannot use a cursor because of the reasons mentioned 66 * above, it will try the fallback cursor. Fallback cursors can themselves have 67 * fallback cursors again, so it is possible to provide a chain of progressively 68 * easier to support cursors. If none of the provided cursors can be supported, 69 * the default cursor will be the ultimate fallback. 70 */ 71 public class Cursor : ObjectG 72 { 73 /** the main Gtk struct */ 74 protected GdkCursor* gdkCursor; 75 76 /** Get the main Gtk struct */ 77 public GdkCursor* getCursorStruct(bool transferOwnership = false) 78 { 79 if (transferOwnership) 80 ownedRef = false; 81 return gdkCursor; 82 } 83 84 /** the main Gtk struct as a void* */ 85 protected override void* getStruct() 86 { 87 return cast(void*)gdkCursor; 88 } 89 90 /** 91 * Sets our main struct and passes it to the parent class. 92 */ 93 public this (GdkCursor* gdkCursor, bool ownedRef = false) 94 { 95 this.gdkCursor = gdkCursor; 96 super(cast(GObject*)gdkCursor, ownedRef); 97 } 98 99 100 /** */ 101 public static GType getType() 102 { 103 return gdk_cursor_get_type(); 104 } 105 106 /** 107 * Creates a new cursor by looking up @name in the current cursor 108 * theme. 109 * 110 * A recommended set of cursor names that will work across different 111 * platforms can be found in the CSS specification: 112 * 113 * | | | | | 114 * | --- | --- | ---- | --- | 115 * | "none" |  "default" |  "help" |  "pointer" | 116 * |  "context-menu" |  "progress" |  "wait" |  "cell" | 117 * |  "crosshair" |  "text" |  "vertical-text" |  "alias" | 118 * |  "copy" |  "no-drop" |  "move" |  "not-allowed" | 119 * |  "grab" |  "grabbing" |  "all-scroll" |  "col-resize" | 120 * |  "row-resize" |  "n-resize" |  "e-resize" |  "s-resize" | 121 * |  "w-resize" |  "ne-resize" |  "nw-resize" |  "sw-resize" | 122 * |  "se-resize" |  "ew-resize" |  "ns-resize" |  "nesw-resize" | 123 * |  "nwse-resize" |  "zoom-in" |  "zoom-out" | | 124 * 125 * Params: 126 * name = the name of the cursor 127 * fallback = %NULL or the `GdkCursor` to fall back to when 128 * this one cannot be supported 129 * 130 * Returns: a new `GdkCursor`, or %NULL if there is no 131 * cursor with the given name 132 * 133 * Throws: ConstructionException GTK+ fails to create the object. 134 */ 135 public this(string name, Cursor fallback) 136 { 137 auto __p = gdk_cursor_new_from_name(Str.toStringz(name), (fallback is null) ? null : fallback.getCursorStruct()); 138 139 if(__p is null) 140 { 141 throw new ConstructionException("null returned by new_from_name"); 142 } 143 144 this(cast(GdkCursor*) __p, true); 145 } 146 147 /** 148 * Creates a new cursor from a `GdkTexture`. 149 * 150 * Params: 151 * texture = the texture providing the pixel data 152 * hotspotX = the horizontal offset of the “hotspot” of the cursor 153 * hotspotY = the vertical offset of the “hotspot” of the cursor 154 * fallback = the `GdkCursor` to fall back to when 155 * this one cannot be supported 156 * 157 * Returns: a new `GdkCursor` 158 * 159 * Throws: ConstructionException GTK+ fails to create the object. 160 */ 161 public this(Texture texture, int hotspotX, int hotspotY, Cursor fallback) 162 { 163 auto __p = gdk_cursor_new_from_texture((texture is null) ? null : texture.getTextureStruct(), hotspotX, hotspotY, (fallback is null) ? null : fallback.getCursorStruct()); 164 165 if(__p is null) 166 { 167 throw new ConstructionException("null returned by new_from_texture"); 168 } 169 170 this(cast(GdkCursor*) __p, true); 171 } 172 173 /** 174 * Returns the fallback for this @cursor. 175 * 176 * The fallback will be used if this cursor is not available on a given 177 * `GdkDisplay`. For named cursors, this can happen when using nonstandard 178 * names or when using an incomplete cursor theme. For textured cursors, 179 * this can happen when the texture is too large or when the `GdkDisplay` 180 * it is used on does not support textured cursors. 181 * 182 * Returns: the fallback of the cursor or %NULL 183 * to use the default cursor as fallback 184 */ 185 public Cursor getFallback() 186 { 187 auto __p = gdk_cursor_get_fallback(gdkCursor); 188 189 if(__p is null) 190 { 191 return null; 192 } 193 194 return ObjectG.getDObject!(Cursor)(cast(GdkCursor*) __p); 195 } 196 197 /** 198 * Returns the horizontal offset of the hotspot. 199 * 200 * The hotspot indicates the pixel that will be directly above the cursor. 201 * 202 * Note that named cursors may have a nonzero hotspot, but this function 203 * will only return the hotspot position for cursors created with 204 * [ctor@Gdk.Cursor.new_from_texture]. 205 * 206 * Returns: the horizontal offset of the hotspot or 0 for named cursors 207 */ 208 public int getHotspotX() 209 { 210 return gdk_cursor_get_hotspot_x(gdkCursor); 211 } 212 213 /** 214 * Returns the vertical offset of the hotspot. 215 * 216 * The hotspot indicates the pixel that will be directly above the cursor. 217 * 218 * Note that named cursors may have a nonzero hotspot, but this function 219 * will only return the hotspot position for cursors created with 220 * [ctor@Gdk.Cursor.new_from_texture]. 221 * 222 * Returns: the vertical offset of the hotspot or 0 for named cursors 223 */ 224 public int getHotspotY() 225 { 226 return gdk_cursor_get_hotspot_y(gdkCursor); 227 } 228 229 /** 230 * Returns the name of the cursor. 231 * 232 * If the cursor is not a named cursor, %NULL will be returned. 233 * 234 * Returns: the name of the cursor or %NULL 235 * if it is not a named cursor 236 */ 237 public string getName() 238 { 239 return Str.toString(gdk_cursor_get_name(gdkCursor)); 240 } 241 242 /** 243 * Returns the texture for the cursor. 244 * 245 * If the cursor is a named cursor, %NULL will be returned. 246 * 247 * Returns: the texture for cursor or %NULL 248 * if it is a named cursor 249 */ 250 public Texture getTexture() 251 { 252 auto __p = gdk_cursor_get_texture(gdkCursor); 253 254 if(__p is null) 255 { 256 return null; 257 } 258 259 return ObjectG.getDObject!(Texture)(cast(GdkTexture*) __p); 260 } 261 }